package day02;

public class Demo03 {
    ThreadLocal<String> val = new ThreadLocal<>();
    public static void main(String[] args) {
        Demo03 demo = new Demo03();
        demo.test();
        demo.demo();
    }
    void test(){
        Thread t1 = new Thread(){
            @Override
            public void run() {
                val.set("Test T1");
                demo();
                demo2();
            }
        };
        t1.start();
        Thread t2 = new Thread(){
            @Override
            public void run() {
                val.set("Test T2");
                demo();
                demo2();
            }
        };
        t2.start();
    }
    public void demo(){
        Thread thread = Thread.currentThread();
        String str = val.get();
        System.out.println(str+","+thread);
    }

    public void demo2(){
        Thread thread = Thread.currentThread();
        String str = val.get();
        System.out.println(str+","+thread);
    }
}
